/**************************************************************************
 Name         : PVRCodecApi.h
 Title        : PVRCodecApi.h
 Author       : PowerVR
 Created      : March 2005

 Copyright    : 2005 by Imagination Technologies Limited. All rights reserved.
              : No part of this software, either material or conceptual 
              : may be copied or distributed, transmitted, transcribed,
              : stored in a retrieval system or translated into any 
              : human or computer language in any form by any means,
              : electronic, mechanical, manual or other-wise, or 
              : disclosed to third parties without the express written
              : permission of Imagination Technologies Limited, Unit 8, HomePark
              : Industrial Estate, King's Langley, Hertfordshire,
              : WD4 8LZ, U.K.

 Description  : PVRCodec API Header file

 Platform     : Generic
 Version	  : $Revision: 1.9 $
 Modifications	: 
 $Log: PVRCodecAPI.h,v $

  --- Revision Logs Removed --- 

  --- Revision Logs Removed --- 

  --- Revision Logs Removed --- 

  --- Revision Logs Removed --- 

  --- Revision Logs Removed --- 

  --- Revision Logs Removed --- 

  --- Revision Logs Removed --- 

  --- Revision Logs Removed --- 

 
*******************************************************************************/

#ifndef _PVRCODEC_API_
#define _PVRCODEC_API_

#ifdef PVRCODECAPI_EXPORTS
#define PVRCODEC_API __declspec(dllexport)
#else
#define PVRCODEC_API
#endif

/** include files **/
#include "img_types.h"
#include "PVRReturnCode.h"


/** local definitions **/
typedef struct SURFACE_TAG*		PVR_SURFACE;
typedef struct INSTANCE_TAG*	PVR_INSTANCE;
typedef struct BUFFER_TAG*		PVR_BUFFER;


/* Surface format types */
typedef enum 
{
	PVR_SURF_FORMAT_420_YV12,	/* YV12 */
	PVR_SURF_FORMAT_420_IMC2,	/* IMC2 */

	PVR_SURF_UNSPECIFIED,

} PVR_SURF_FORMAT;

typedef struct
{
	IMG_UINT32 ui32Width;
	IMG_UINT32 ui32Height;
	IMG_UINT32 ui32PhysWidth;
	IMG_UINT32 ui32PhysHeight;
} PVR_SURF_COMPONENT_INFO;

typedef enum
{
	PVR_WMV_9,
	PVR_WMV_8,
	PVR_MPEG1,
	PVR_MPEG2,
	PVR_MPEG4_SP,
	PVR_MPEG4_ASP,
	PVR_H263_PROFILE0,
	PVR_H264_BASELINE,
	PVR_H264_BASELINE_LB,
	PVR_H264_DB,

	PVR_UNSPECIFIED
} PVR_VIDEOSTANDARD;

/* API types */
typedef enum
{
	PVR_VDA,
	PVR_VEA,
	PVR_JPEG,
    PVR_NUM_API_TYPES,
} PVR_API_TYPE;

typedef enum
{
	PVR_AC_DEFAULT,
	PVR_AC_ENABLE,
	PVR_AC_DISABLE,
	PVR_AC_INVALID
} PVR_AC_CONTROL;



#ifdef __cplusplus
extern "C" {  
#endif	

/***********************************************************************************
 Function Name      : PVRVEAInitialiseEncoder
 Inputs             : eAPIType,eVideoStandard 
 Outputs            : *phInstance
 Returns            : PVRRC
 Description        : Initialises the Encoder and acquires exclusive access to hw
************************************************************************************/
PVRCODEC_API PVRRC PVRInitialise(	/*out */	PVR_INSTANCE	*phInstance,
									/*in */	PVR_API_TYPE		eAPIType,
									/*in */	PVR_VIDEOSTANDARD	eVideoStandard);

typedef PVRRC (*fnPVRInitialise)(	/*out */	PVR_INSTANCE	*phInstance,
									/*in */	PVR_API_TYPE		eAPIType,
									/*in */	PVR_VIDEOSTANDARD	eVideoStandard);

/***********************************************************************************
 Function Name      : PVRVEADeinitialise
 Inputs             : hInstance,
 Outputs            : 
 Returns            : PVRRC
 Description        : Deinitialise the encoder and release access to the hardware
 ************************************************************************************/
PVRCODEC_API PVRRC PVRDeinitialise(	/*in*/ PVR_INSTANCE hInstance);

typedef PVRRC (*fnPVRDeinitialise)(	/*in*/ PVR_INSTANCE hInstance);

/***********************************************************************************
 Function Name      : PVRSurfaceAllocate
 Inputs             : hInstance,ui32FrameWidth,ui32FrameHeight,eSurfaceFormat
						ui32SurfaceCount
 Outputs            : ahSurface
 Returns            : PVRRC
 Description        : Allocates memory for Surface planes
 ************************************************************************************/
PVRCODEC_API PVRRC PVRSurfaceAllocate(	/*in */ PVR_INSTANCE		hInstance, 
									    /*in */ IMG_UINT32			ui32FrameWidth,
									    /*in */ IMG_UINT32			ui32FrameHeight,
										/*in */ PVR_SURF_FORMAT	eSurfaceFormat,
										/*in */ IMG_UINT32			ui32SurfaceCount,
									    /*out*/ PVR_SURFACE			ahSurface[]);

typedef PVRRC (*fnPVRSurfaceAllocate)(	/*in */ PVR_INSTANCE		hInstance, 
									    /*in */ IMG_UINT32			ui32FrameWidth,
									    /*in */ IMG_UINT32			ui32FrameHeight,
										/*in */ PVR_SURF_FORMAT	eSurfaceFormat,
										/*in */ IMG_UINT32			ui32SurfaceCount,
									    /*out*/ PVR_SURFACE			ahSurface[]);


/***********************************************************************************
 Function Name      : PVRSurfaceCreate
 Inputs             : hInstance,ui32FrameWidth,ui32FrameHeight,eSurfaceFormat
						ui32SurfaceCount
 Outputs            : ahSurface
 Returns            : PVRRC
 Description        : Similar to PVRSurfaceAllocate above except that the memory 
                      buffer is provided by the caller.
 ************************************************************************************/

PVRCODEC_API PVRRC PVRSurfaceCreate(PVR_INSTANCE		hInstance, 
									  IMG_UINT32		ui32FrameWidth,
									  IMG_UINT32		ui32FrameHeight,
									  IMG_UINT8		*pui8SurfaceBufferUserAddr,
									  PVR_SURF_FORMAT	eSurfaceFormat,
									  IMG_UINT32		ui32SurfaceCount,
									  PVR_SURFACE		ahSurface[]);


/***********************************************************************************
 Function Name      : PVRSurfaceAllocateEx
 Inputs             : hInstance,pui32Info,ui32ComponentCount
 Outputs            : phSurface
 Returns            : PVRRC
 Description        : Allocation of non defined surface types
 ************************************************************************************/
PVRCODEC_API PVRRC PVRSurfaceAllocateRaw(	/*in */	PVR_INSTANCE				hInstance, 
											/*in */	PVR_SURF_COMPONENT_INFO		pui32Info[],
											/*in */ IMG_UINT32					ui32ComponentCount,
											/*out*/ PVR_SURFACE*				phSurface);

typedef PVRRC (*fnPVRSurfaceAllocateRaw)(	/*in */	PVR_INSTANCE				hInstance, 
											/*in */	PVR_SURF_COMPONENT_INFO		pui32Info[],
											/*in */ IMG_UINT32					ui32ComponentCount,
											/*out*/ PVR_SURFACE*				phSurface);

/***********************************************************************************
 Function Name      : PVRSurfaceSync
 Inputs             : hInstance,hSurface,bWait
 Outputs            : 
 Returns            : PVRRC
 Description        : Allows syncronise with the last operation on the given surface.
 ************************************************************************************/

 PVRCODEC_API PVRRC PVRSurfaceSync(	/*in */	PVR_INSTANCE 	hInstance,
									/*in */ PVR_SURFACE 		hSurface,
									/*in */ IMG_BOOL 			bWait);

typedef PVRRC (*fnPVRSurfaceSync)(	/*in */	PVR_INSTANCE 	hInstance,
									/*in */ PVR_SURFACE 		hSurface,
									/*in */ IMG_BOOL 			bWait);

/***********************************************************************************
 Function Name      : PVRSurfaceLock
 Inputs             : hInstance,hSurface,bWait
 Outputs            : pui8ComponentBytes,pui32Info
 Returns            : PVRRC
 Description        : Locks the surface for use by application and provides details of 
						Surface planes.
 ************************************************************************************/
PVRCODEC_API PVRRC PVRSurfaceLock( /*in */ PVR_INSTANCE					hInstance,
								   /*in */ PVR_SURFACE					hSurface, 
								   /*out*/ IMG_UINT8					*pui8ComponentBytes[],
								   /*out*/ PVR_SURF_COMPONENT_INFO		paSurfInfo[],
								   /*in */ IMG_BOOL						bWait);

typedef PVRRC (*fnPVRSurfaceLock)( /*in */ PVR_INSTANCE					hInstance,
								   /*in */ PVR_SURFACE					hSurface, 
								   /*out*/ IMG_UINT8					*pui8ComponentBytes[],
								   /*out*/ PVR_SURF_COMPONENT_INFO		paSurfInfo[],
								   /*in */ IMG_BOOL						bWait);

/***********************************************************************************
 Function Name      : PVRSurfaceUnlock
 Inputs             : hInstance,hSurface,bWait
 Outputs            : 
 Returns            : PVRRC
 Description        : Removes the application lock on the surface.
 ************************************************************************************/
PVRCODEC_API PVRRC PVRSurfaceUnlock(/*in */ PVR_INSTANCE hInstance,
									/*in */ PVR_SURFACE hSurface);


typedef PVRRC (*fnPVRSurfaceUnlock)(/*in */ PVR_INSTANCE hInstance,
									/*in */ PVR_SURFACE hSurface);

/***********************************************************************************
 Function Name      : PVRSurfaceFree
 Inputs             : hInstance,ui32SurfaceCount,ahSurface
 Outputs            : 
 Returns            : PVRRC
 Description        : Frees all memory associated with the surface.
 ************************************************************************************/
PVRCODEC_API PVRRC PVRSurfaceFree( /*in */ PVR_INSTANCE		hInstance,
								   /*in */ IMG_UINT32		ui32SurfaceCount,
								   /*in */ PVR_SURFACE		ahSurface[]);

typedef PVRRC (*fnPVRSurfaceFree)( /*in */ PVR_INSTANCE		hInstance,
								   /*in */ IMG_UINT32		ui32SurfaceCount,
								   /*in */ PVR_SURFACE		ahSurface[]);


PVRCODEC_API PVRRC PVRSurfaceDestroy(/*in */ PVR_INSTANCE		hInstance,
                                     /*in */ IMG_UINT32		    ui32SurfaceCount,
                                     /*in */ PVR_SURFACE		ahSurface[]);
                                     
PVRCODEC_API PVRRC PVRSurfaceGetAttr(PVR_INSTANCE		hInstance, 
					IMG_UINT32		ui32FrameWidth,
					IMG_UINT32		ui32FrameHeight,
					PVR_SURF_FORMAT		eSurfaceFormat,
					IMG_UINT32		*pui32SurfaceSize);


/***********************************************************************************
 Function Name      : PVRGetErrorCodeString
 Inputs             : eErrorCode
 Outputs            : 
 Returns            : const char*
 Description        : Returns a pointer to string assosiated with the error code
 ************************************************************************************/
PVRCODEC_API const char* PVRGetErrorCodeString( PVRRC eErrorCode );

PVRCODEC_API PVRRC PVRGetPhysical(IMG_UINT32 pVirtualAddress,IMG_UINT32	pPhysicalAddress);


typedef struct
{
	fnPVRInitialise			PVRInitialise;
	fnPVRDeinitialise		PVRDeinitialise;
	fnPVRSurfaceAllocate	PVRSurfaceAllocate;
	fnPVRSurfaceAllocateRaw	PVRSurfaceAllocateRaw;
	fnPVRSurfaceSync		PVRSurfaceSync;
	fnPVRSurfaceLock		PVRSurfaceLock;
	fnPVRSurfaceUnlock		PVRSurfaceUnlock;
	fnPVRSurfaceFree		PVRSurfaceFree;
} PVRCodecAPI;


#define VALIDATE_POINTER_EX(p,rc) if (NULL==p)\
	{\
        RETAILMSG(1,(TEXT("%s: ERROR: Invalid pointer.\r\n"),TEXT(__FUNCTION__)));\
		return (rc) ;\
	}

#define VALIDATE_POINTER(p) VALIDATE_POINTER_EX(p,PVRRC_INVALID_PARAMETER)

#define VALIDATE_IMG_BOOL(p) if (p!=IMG_TRUE && p!=IMG_FALSE)\
	{\
        RETAILMSG(1,(TEXT("%s: ERROR: Bad IMG_BOOL value: %d.\r\n"),TEXT(__FUNCTION__),p));\
		return PVRRC_INVALID_PARAMETER ;\
    }
	

//#define ENTER (gFrameCount<4)
#define ENTER 0

void MvedPowerSetIdle   (PVR_INSTANCE hInstance) ;
void MvedPowerSetActive (PVR_INSTANCE hInstance) ;

#ifdef __cplusplus
}
#endif


#endif
